<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    div{
      width: 0;
      height: 0;
      border-top: 40px solid;
      border-left: 50px solid transparent;
      border-right: 30px solid transparent;
    }
  </style>
</head>
<body>
  <div></div>
  <script>
      let obj = {
        name: 'dami',
        age: 18,
        fans: {name: 'aa', fans: {name: 'bb'}}
      }

      function deepClone(source){
        
        if(!(source instanceof Object) || source === {}){
          return;
        }

        let target = {}
        for(let i in source){
          // 复杂类型
          console.log(i);
          if(typeof source[i] === 'object'){
            if(source.hasOwnProperty(i)){
              target[i] = deepClone(source[i])
            }
          }else{
            //简单类型
            target[i] = source[i]
          }
        }
        return target;
      }

      function cloneLoop(x) {
        const root = {};

        // 栈
        const loopList = [
            {
                parent: root,
                key: undefined,
                data: x,
            }
        ];

        while(loopList.length) {
            // 深度优先
            const node = loopList.pop(); //length--
            const parent = node.parent;
            const key = node.key;
            const data = node.data;

            // 初始化赋值目标，key为undefined则拷贝到父元素，否则拷贝到子元素
            let res = parent;
            if (typeof key !== 'undefined') {
                //？？
                res = parent[key] = {};
            }

            for(let k in data) {
                if (data.hasOwnProperty(k)) {
                    if (typeof data[k] === 'object') {
                        // 下一次循环
                        loopList.push({
                            parent: res,
                            key: k,
                            data: data[k],
                        });
                    } else {
                        res[k] = data[k];
                    }
                }
            }
        }

        return root;
    }

  var arr=[2,8,5,0,5,2,6,7,2];
  function unique1(arr){
    var hash=[];
    for (var i = 0; i < arr.length; i++) {
      if(hash.indexOf(arr[i])==-1){
        hash.push(arr[i]);
      }
    }
    return hash;
  }
  </script>
</body>
</html>